
#include <bits/stdc++.h>
const int MAXN = 3e5 + 5;
int cnt[MAXN];

int main() {
  int n, l;
  scanf("%d%d", &n, &l);
  int p = 0;
  ++cnt[p];
  for (int i = 1; i <= n - 1; ++i) {
    int d;
    scanf("%d", &d);
    (p += d) %= l;  // p= p+d;  p = p%l;
    ++cnt[p];
  }

  if (l % 3) {
    printf( "%d", 0);
    return 0;
  }
  long long ans = 0;
  for (int a = 0; a < l / 3; ++a) {
    int b = a + l / 3;
    int c = a + 2 * l / 3;
    ans += 1ll * cnt[a] * cnt[b] * cnt[c];
  }
  printf("%lld\n", ans);
  return 0;
}